/**
 * 
 * 主执行栈
 *      向操作系统发指令要求，异步读取一个文件 callback放到宏任务队列
 * 微任务队列
 *      process.nextTick() 的回调函数
 * 宏任务队列
 *      setTimeout fs.readFile() 的回调函数队列
 * 
 */

let buf1 = Buffer.alloc(6)
console.log(buf1)

let buf2 = Buffer.allocUnsafe(6);
console.log(buf2)

let buf3 = Buffer.from('珠峰')
console.log(buf3)


let buf4 = Buffer.alloc(6)
// buf4.fill(3, 1, 3) // 填充的值 填充的开始索引 结束索引

buf4.write("珠峰", 0, 3, 'utf8')
buf4.write("峰", 3, 6, 'utf8')
console.log(buf4.toString())

let {StringDecoder} = require("string_decoder")
let buf9 = Buffer.from("珠峰培训5")
console.log(buf9)
let buf10 = buf9.slice(0,5)
let buf11 = buf9.slice(5)

let sd = new StringDecoder()
console.log(sd.write(buf10)) // 读取buffer内容，返回一个字符串 把不完整的缓存起来
console.log(sd.write(buf11)) 


